package servlet;

import dao.Dao;
import domain.Goods;
import domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/catchUserGoodInfoServlet")
public class CatchUserGoodInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        if (request.getSession().getAttribute("user_login") == null) {
            request.setAttribute("message", "您还未登录，请先登录");
            request.getRequestDispatcher("/userLogin.jsp").forward(request, response);
        } else {
            String sid = request.getParameter("sid");
            String suserid = request.getParameter("suserid");
            Dao dao = new Dao();
            User user_shoppingCar = dao.findUserById(Integer.valueOf(suserid));
            Goods good_shoppingCar = dao.findGoodByCid(sid);
            request.setAttribute("good_shoppingCar", good_shoppingCar);
            request.setAttribute("user_shoppingCar", user_shoppingCar);
            request.getRequestDispatcher("/ShoppingCarInfo.jsp").forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
